home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / guidegrid < prev    next >
Encoding:
Text File  |  2000-05-21  |  2.2 KB  |  88 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5.  
  6. # <sjburges@gimp.org> (original release)
  7. #
  8. # 11/7/99 <brendy@swipnet.se>
  9. # Added an option to remove existing guides
  10. # Added progress bar.
  11. # ** How can we force the display to update after adding guides? **
  12. #
  13. # 12/7/99 <sjburges@gimp.org>
  14. # Changed the display code in C and got rid of ugly hack in perl.
  15. #
  16. use Gimp;
  17. use Gimp::Fu;
  18. use Gimp::Util;
  19.  
  20. # Gimp::set_trace(TRACE_ALL);
  21.  
  22. register "guide_grid",
  23.   "GuideGrid - creates a grid of guides\n",
  24.   "You specify the X spacing, the Y spacing, and initial offsets.  It creates a grid of guides\n",
  25.   "Seth Burgess",
  26.   "Seth Burgess <sjburges\@gimp.org>",
  27.   "1999-03-20",
  28.   N_"<Image>/Guides/Guide Grid...",
  29.   "*",
  30.   [
  31.    [PF_SPINNER, "x_spacing", "How far to space grid horizontally", 24, [1,1000,1]],
  32.    [PF_SPINNER, "y_spacing", "How far to space grid vertically", 24, [1,1000,1]],
  33.    [PF_SPINNER, "x_offset", "How much to initially offset it horizontally", 0, [0,1000,1]],
  34.    [PF_SPINNER, "y_offset", "How much to initially offset it vertically", 0, [0,1000,1]],
  35.    [PF_TOGGLE, "remove_old_guides", "Remove existing guides?", 0],
  36.   ],
  37.   [],
  38.   ['gimp-1.1'],
  39.   sub {
  40.     my($img,$layer,$xspace, $yspace, $xoffset, $yoffset, $remove_old_guides) =@_;
  41.  
  42.     #
  43.     # Remove all existing guides (this is optional)
  44.     #    
  45.     if($remove_old_guides) {
  46.       $i=$img->find_next_guide(0);
  47.       while ($i != 0) {
  48.         $img->delete_guide($i);
  49.         $i=$img->find_next_guide(0);
  50.       }         
  51.     }
  52.  
  53.     #
  54.     # Add vertical guides to the image
  55.     #
  56.     for ($i=$xoffset; $i<$img->width; $i+=$xspace) {
  57.       if ($i) {
  58.     $img->add_vguide($i);
  59.       }
  60.     }
  61.     
  62.     #
  63.     # Add horizontal guides to the image
  64.     #
  65.     for ($i=$yoffset; $i<$img->height; $i+=$yspace) {
  66.       if ($i) {
  67.     $img->add_hguide($i);
  68.       }
  69.     }
  70.     
  71.     # 
  72.     # I fixed this in Gimp C code (it wasn't flushing guides properly) 
  73.     # Seth Burgess <sjburges@gimp.org>
  74.     #
  75.  
  76.     ##
  77.     ## Refresh the display (probably not good, works for me!)
  78.     ##
  79.     ##
  80.     #$img->selection_all();
  81.     #$img->selection_none();
  82.  
  83.     $layer->update(0, 0, $img->height, $img->width);
  84.  
  85.     return();
  86.   };
  87. exit main;
  88.